﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package com.yy.manager {
    import com.yy.base.App;
    import com.yy.ui.events.UIEvent;
    
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;

    public class FullScreenPanelManager extends EventDispatcher {

        private var modalSprite:Sprite;
        private var panelModalDic:Dictionary;
        private var _stage:Stage;
        private var _parent:DisplayObjectContainer;
        private var panelList:Array;

        public function FullScreenPanelManager(){
            this._stage = App.appStage;
            this.modalSprite = new Sprite();
            this.modalSprite.graphics.beginFill(0, 0.5);
            this.modalSprite.graphics.drawRect(0, 0, 10, 10);
            this.modalSprite.graphics.endFill();
            this.modalSprite.width = this._stage.stageWidth;
            this.modalSprite.height = this._stage.stageHeight;
            this.panelModalDic = new Dictionary();
            this.panelList = [];
            this._stage.addEventListener(Event.RESIZE, this.resizeHandler);
        }
        public function addPanel(_arg1:DisplayObject, _arg2:Boolean=false):void{
            var _local3:int;
            this.panelModalDic[_arg1] = _arg2;
            this.panelList.push(_arg1);
            if ((((this.panelList.length > 0)) && (!((this.panelList[(this.panelList.length - 1)] == _arg1))))){
            } else {
                this._addPanel(_arg1);
            };
            var _local4:UIEvent = new UIEvent(UIEvent.SCREENPANEL_OPEN);
            _local4.data = _arg1;
            dispatchEvent(_local4);
        }
        private function _addPanel(_arg1:DisplayObject):void{
            _arg1.visible = true;
            if (this.panelModalDic[_arg1]){
                this.parent.addChild(this.modalSprite);
            };
            this.addPanelToStage(_arg1);
        }
        protected function addPanelToStage(_arg1:DisplayObject):void{
            var _local2:Number;
            var _local3:Number;
            this.parent.addChild(_arg1);
            var _local4:Number = 0.5;
            _arg1.x = 0;
            _arg1.y = 0;
            var _local5:UIEvent = new UIEvent(UIEvent.POPUP_COMPLETE);
            dispatchEvent(_local5);
        }
        private function panelComplete():void{
            var _local1:UIEvent = new UIEvent(UIEvent.POPUP_COMPLETE);
            dispatchEvent(_local1);
        }
        public function removePanel(_arg1:DisplayObject):void{
            if (((_arg1) && (this.parent.contains(_arg1)))){
                this.removePanelToStage(_arg1);
            };
            if (this.parent.contains(this.modalSprite)){
                this.parent.removeChild(this.modalSprite);
            };
            delete this.panelModalDic[_arg1];
            var _local2:int = this.panelList.indexOf(_arg1);
            if (_local2 != -1){
                this.panelList.splice(_local2, 1);
            };
            if ((((this.panelList.length > 0)) && ((_local2 == this.panelList.length)))){
                this._addPanel((this.panelList[(this.panelList.length - 1)] as DisplayObject));
            };
            var _local3:UIEvent = new UIEvent(UIEvent.SCREENPANEL_CLOSE);
            _local3.data = _arg1;
            dispatchEvent(_local3);
        }
        protected function removePanelToStage(_arg1:DisplayObject):void{
            this.parent.removeChild(_arg1);
        }
        public function get parent():DisplayObjectContainer{
            return (((this._parent) || (this._stage)));
        }
        public function set parent(_arg1:DisplayObjectContainer):void{
            this._parent = _arg1;
        }
        public function getPanel():DisplayObject{
            if (this.panelList.length > 0){
                return (this.panelList[(this.panelList.length - 1)]);
            };
            return (null);
        }
        public function getPanelList():Array{
            return (this.panelList);
        }
        private function resizeHandler(_arg1:Event):void{
            this._resizeHandler(this._stage.stageWidth, this._stage.stageHeight);
        }
        protected function _resizeHandler(_arg1:Number, _arg2:Number):void{
            var _local3:DisplayObject = this.getPanel();
            if (_local3 != null){
                _local3.width = _arg1;
                _local3.height = _arg2;
            };
            this.modalSprite.width = _arg1;
            this.modalSprite.height = _arg2;
        }

    }
}//package com.fminutes.vinciUI.manager 
